﻿using System;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections.Generic;

namespace WS.DAL
{
    using SKG.DAL;
    using Entities;

    public abstract class NguoidungDAL : BaseDAL, IBase
    {
        #region Implement
        /// <summary>
        /// Count number of records
        /// </summary>
        /// <returns></returns>
        public int Count()
        {
            try
            {
                var tb = Mapper.QueryForDataTable("Nguoidung_Count", null);
                if (tb == null) return 0;
                return tb.Rows.Count;
            }
            catch { return 0; }
        }

        /// <summary>
        /// Return data by foreign key
        /// </summary>
        /// <param name="fKey">Foreign key on this table</param>
        /// <returns></returns>
        public DataTable Select(Guid fKey)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Select user by account
        /// </summary>
        /// <param name="code">User's account</param>
        /// <returns></returns>
        public object Select(string code)
        {
            try
            {
                return Mapper.QueryForDataTable("Nguoidung_Select_By_Taikhoan", null);
            }
            catch { return null; }
        }

        /// <summary>
        /// Return data
        /// </summary>
        /// <param name="obj">Object of entity</param>
        /// <param name="skip">Skip number of records</param>
        /// <param name="take">Take number of records</param>
        /// <returns></returns>
        public DataTable Select(object obj = null, int skip = 0, int take = 0)
        {
            try
            {
                return Mapper.QueryForDataTable("Nguoidung_Select_All", null);
            }
            catch { return _tb; }
        }

        /// <summary>
        /// Insert data
        /// </summary>
        /// <param name="obj">Object of entity</param>
        /// <returns></returns>
        public object Insert(object obj)
        {
            try
            {
                return _sqlMapper.Insert("Nguoidung_Insert", obj);
            }
            catch { return null; }
        }

        /// <summary>
        /// Update data
        /// </summary>
        /// <param name="obj">Object of entity</param>
        /// <returns></returns>
        public object Update(object obj)
        {
            try
            {
                return _sqlMapper.Update("Nguoidung_Update", obj);
            }
            catch { return null; }
        }

        /// <summary>
        /// Delete data
        /// </summary>
        /// <param name="id">Primary key</param>
        /// <returns></returns>
        public object Delete(Guid id = new Guid())
        {
            try
            {
                return _sqlMapper.Delete("Nguoidung_Delete", id);
            }
            catch { return null; }
        }
        #endregion

        /// <summary>
        /// Update password
        /// </summary>
        /// <param name="o">Pol_User</param>
        /// <returns></returns>
        protected object UpdatePass(Nguoidung o)
        {
            try
            {
                return _sqlMapper.Update("Nguoidung_Update_Matkhau", o);
            }
            catch { return null; }
        }

        public DataTable Select_By_Taikhoan(string code)
        {
            try
            {
                return Mapper.QueryForDataTable("Nguoidung_Select_By_Taikhoan", code);
            }
            catch { return null; }
        }
    }
}